import datetime
from haystack import indexes
from apps.demomanager.models import Demo


class DemoIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    title = indexes.CharField(model_attr='title')
    content = indexes.CharField(model_attr='content')
    last_update = indexes.DateTimeField(model_attr='last_update')

    def get_model(self):  # 重载get_model方法，必须要有！
        return Demo

    def index_queryset(self, using=None):  # 重载index_..函数
        """Used when the entire index for model is updated."""
        return self.get_model().objects.filter(last_update__lte=datetime.datetime.now())